package com.jackie.coupon.claculation.services.impl;

import com.alibaba.fastjson.JSON;
import com.jackie.coupon.claculation.api.ShoppingCart;
import com.jackie.coupon.claculation.api.SimulationOrder;
import com.jackie.coupon.claculation.api.SimulationResponse;
import com.jackie.coupon.claculation.services.CouponCalculationService;
import com.jackie.coupon.claculation.template.CouponTemplateFactory;
import com.jackie.coupon.claculation.template.RuleTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * CouponCalculationServiceImpl
 *
 * @author Jackie Hou
 * @date 2023/11/17 16:36
 * @version 1.0
 */
@Slf4j
@Service
public class CouponCalculationServiceImpl implements CouponCalculationService {

    @Override
    public ShoppingCart calculateOrderPrice(ShoppingCart cart) {
        log.info("calculate order price: {}", JSON.toJSONString(cart));
        RuleTemplate ruleTemplate = couponTemplateFactory.getTemplate(cart);
        return ruleTemplate.calculate(cart);
    }

    @Override
    public SimulationResponse simulate(SimulationOrder order) {
        return null;
    }

    @Autowired
    private CouponTemplateFactory couponTemplateFactory;
}
